{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 练习2 计算函数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "x = eval(input(\"请输入x:\"))\n",
    "y = 0\n",
    "if x < -4:\n",
    "    y = x + 9\n",
    "elif x < 4:\n",
    "    y = x*x + x*2 + 1\n",
    "else:\n",
    "    y = 2*x -15\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 判定学生成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "math = eval(input(\"请输入数学成绩(0-100):\"))\n",
    "if math>85:\n",
    "    print(\"优秀\")\n",
    "elif math>70:\n",
    "    print(\"良好\")\n",
    "elif math>60:\n",
    "    print(\"及格\")\n",
    "else:   \n",
    "    print(\"不及格\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8 斐波那契数列\n",
    "1 1 2 3 5 8 13 21 ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 "
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "b = 1\n",
    "print(a,b,end=\" \")\n",
    "for i in range(18):\n",
    "    c = a+b\n",
    "    print(c,end=\" \")\n",
    "    # print(a,\"+\",b,\"=\",c)\n",
    "    # 将当前b和c放入a和b用于下一次计算\n",
    "    a,b= b,c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
